import request from '@/utils/request'

// 查询工单附件列表
export function listAttachment(query) {
  return request({
    url: '/sbtz/attachment/list',
    method: 'get',
    params: query
  })
}

// 查询工单附件详细
export function getAttachment(id) {
  return request({
    url: '/sbtz/attachment/' + id,
    method: 'get'
  })
}

// 新增工单附件
export function addAttachment(data) {
  return request({
    url: '/sbtz/attachment',
    method: 'post',
    data: data
  })
}

// 修改工单附件
export function updateAttachment(data) {
  return request({
    url: '/sbtz/attachment',
    method: 'put',
    data: data
  })
}

// 删除工单附件
export function delAttachment(id) {
  return request({
    url: '/sbtz/attachment/' + id,
    method: 'delete'
  })
}

// 列表
export function listAttachments(orderId) {
  return request({
    url: `/sbtz/attachment/${orderId}/attachments`,
    method: 'get'
  })
}

// 上传（files: File[], relativePaths: string[] 可选）
export function uploadAttachments(orderId, formData) {
  return request({
    url: `/sbtz/attachment/${orderId}/attachments/upload`,
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  })
}

// 删除
export function delAttachments(ids) {
  return request({
    url: `/sbtz/attachment/attachments/${ids}`,
    method: 'delete'
  })
}

export function downloadOrderAttachmentsZip(params) {
  return request({
    url: '/sbtz/attachment/batch-download',
    method: 'get',
    params,
    responseType: 'blob',   // 👈 关键：拿文件流
    timeout: 0              // 大文件可放开超时（可选）
  })
} 